//
//  StarView.m
//  HuiWenMovie
//
//  Created by ios on 15/7/21.
//  Copyright (c) 2015年 ios. All rights reserved.
//

#import "StarView.h"

@implementation StarView




-(void)awakeFromNib
{
    [self configureStarView];
    
}

- (void)configureStarView
{
    UIImage *image1 = [UIImage imageNamed:@"yellow.png"];
    UIImage *image2 = [UIImage imageNamed:@"gray"];
    _yellowImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image1.size.width*5, image1.size.height)];
    _greyImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image2.size.width*5, image2.size.height)];
    _yellowImageView.backgroundColor = [UIColor colorWithPatternImage:image1];
    _greyImageView.backgroundColor = [UIColor colorWithPatternImage:image2];
    
    float scale = self.frame.size.height/_yellowImageView.frame.size.height;
    
    _greyImageView.transform = CGAffineTransformMakeScale(scale, scale);
    _yellowImageView.transform = CGAffineTransformMakeScale(scale, scale);
    
    CGRect frame = _yellowImageView.frame;
    frame.origin = CGPointZero;
    
    _yellowImageView.frame = frame;
    _greyImageView.frame = frame;
    
    
    [self addSubview:_greyImageView];
    [self addSubview:_yellowImageView];
    NSLog(@"%f",_yellowImageView.frame.size.width);
    NSLog(@"%f",_yellowImageView.frame.size.height);

}
- (void)setAverage:(float)average
{
    _average = average;
    [self setNeedsLayout];

}
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGRect frame = _yellowImageView.frame;
  //  NSLog(@"%f",_average);
    frame.size.width = _average/10*_greyImageView.frame.size.width;
    
    _yellowImageView.frame = frame;
    

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
